﻿using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;



/// <summary>

/// Summary description for Alert1

/// </summary>

public static class Alert
{
    public static void Show(string message)
    {
        // Cleans the message to allow single quotation marks
        message = message.Replace("'", "\\'");
        string script = "Show('" + message + "|" + "اغلاق" + "');";
        // Gets the executing web page
        Page page = HttpContext.Current.CurrentHandler as Page;
        // Checks if the handler is a Page and that the script isn't already on the Page
        //if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("alert"))
        //{
        //    ScriptManager.RegisterStartupScript(page, typeof(Alert), "alert", script, true);
        //}

        if (!page.ClientScript.IsStartupScriptRegistered("alert"))
        {
            ScriptManager.RegisterStartupScript(page, typeof(Alert), "alert", script, true);
        }
    }

    public static void ShowWithoutScriptManager(string message)
    {



        // Cleans the message to allow single quotation marks

        message = message.Replace("'", "\\'");

        string script = "Show('" + message + "|" + "اغلاق" + "');";



        // Gets the executing web page

        Page page = HttpContext.Current.CurrentHandler as Page;



        if (!page.ClientScript.IsStartupScriptRegistered("alert"))
        {

            page.ClientScript.RegisterStartupScript(typeof(Alert), "alert", script, true);

        }

    }

    public static void Show(string message, bool report)
    {
        // Cleans the message to allow single quotation marks
        message = message.Replace("'", "\\'");
        string script = "alert('" + message + "');";
        // Gets the executing web page
        Page page = HttpContext.Current.CurrentHandler as Page;
        if (!page.ClientScript.IsStartupScriptRegistered("alert"))
        {
            ScriptManager.RegisterStartupScript(page, typeof(Alert), "alert", script, true);
        }
    }
    public static void Confirm(string message)
    {
        // Cleans the message to allow single quotation marks
        string cleanMessage = message.Replace("'", "\'");
        string script = "ConfirmNodeDeletion('" + cleanMessage + "|" + "نعم" + "|" + "لا" + "');";
        // Gets the executing web page
        Page page = HttpContext.Current.CurrentHandler as Page;
        if (!page.ClientScript.IsStartupScriptRegistered("confirm"))
        {
            ScriptManager.RegisterStartupScript(page, typeof(Alert), "confirm", script, true);
        }
    }
    public static void OpenNewWindow(string url)
    {
        // Cleans the message to allow single quotation marks
        string script = "window.open('" + url + "');";
        // Gets the executing web page
        Page page = HttpContext.Current.CurrentHandler as Page;
        // Checks if the handler is a Page and that the script isn't already on the Page
        if (!page.ClientScript.IsStartupScriptRegistered("NewWindow"))
        {
            ScriptManager.RegisterStartupScript(page, typeof(Alert), "NewWindow", script, true);
       }

    }

}